/*
 * Noise.h
 *
 *  Created on: Apr 19, 2011
 *      Author: nzhao
 */

#ifndef NOISE_H_
#define NOISE_H_

extern double * POWER_LIST;
extern int IS_WARNING;
extern double MAX_ERROR;

class noise_ensemble
{
public:
	void initialize(double minT, double maxT, int nt, double minW, double maxW, int nw, int num_path, int num_interpolation);
	void generate_bath(int s);
	int num_path(){return npath;};
	int seed(){return rand_seed;};

	double eval(int path_n, double tval);

	void calc_correlation_func(double * res);
	void calc_dephasing(double * coherence_re, double * coherence_im);

	void set_phase_mat(double * ph);

	void calc_phase1(double * res);
	void calc_phase1_gsl_int(double * res, int path_n);
	void calc_phase1_gsl_int1(double * res, int path_n);
	void calc_phase2(double * res, int path_n);
	void calc_phase2_old(double * res);
	void calc_phase2_gsl_int(double * phase2, int path_idx);
	void calc_phaseFull_gsl_int(double * res, int path_idx);
private:
	double maxtime;
	double mintime;
	int ntime;

	double minfrequency;
	double maxfrequency;
	int nfrequency;

	int npath;
	int ninterpolation;

	int rand_seed;

	double * harmonic_mat_sin;
	double * harmonic_mat_cos;
	double * harmonic_mat_sin_interpolation;
	double * harmonic_mat_cos_interpolation;
	double * amplitude_mat_alpha;
	double * amplitude_mat_beta;

	double * interpolation_time_list;
	double * bt_interpolation;
	double * bt_mat;

	double dt;
	double df;

	double * phase_mat;


	double * bilinear_alpha;
	double * bilinear_beta;
	double * bilinear_alpha_beta;

	void generate_interpolation_point(int path_idx, int power);
	void calc_quantity(double * harmonic_sin, double * harmonic_cos, double * res);
	void calc_aa_bb_val(int k, int k1, int i, double * aa_val, double * bb_val);
	double calc_ab(int k, int k1, int i);

	void calc_int_sin_bt_mat(int nt, int nf, double dt, double df, double * int_sin_mat);
	void calc_int_cos_bt_mat(int nt, int nf, double dt, double df, double * int_cos_mat);

	void gen_bilinear_mat();
	void calc_aa_bb_mat(double * aa_mat, double * bb_mat, int ti);
	void calc_ab_mat(double * ab_mat, int ti);

};

#endif /* NOISE_H_ */
